
local mt = {}

mt.type = 'timestamp'

mt.time_stamp = 0

local time_data = {
    ['年'] = '%Y',
    ['月'] = '%m',
    ['日'] = '%d',
    ['时'] = '%H',
    ['分'] = '%M',
    ['秒'] = '%S',
    ['时分秒'] = '%X', --13:12:53
}

-- 获取时间戳
mt.get_time_stamp = function()
    return mt.time_stamp 
end

-- 设置时间戳
mt.set_time_stamp = function (time_stamp)
    mt.time_stamp = time_stamp
end 

-- 获取时间日期 -> 20210326
mt.get_time = function(format)
    return tonumber(os.date(format or "%Y%m%d", mt.get_time_stamp()))
end

-- 获取时间日期 -> 20210326
mt.get_time_str = function(time)
    return os.date("%Y-%m-%d %H:%M:%S", time)
end

-- 获取时间类型 -> get_type_time('年') -> 2021
mt.get_type_time = function(type)
    return os.date(time_data[type], mt.get_time_stamp())
end

-- 判断时间戳是否同一天(参数-日)
mt.is_one_day = function(time1, time2)
    if not time1 or not time2 then
        return false
    end
    return tonumber(os.date("%Y%m%d", time1)) == tonumber(os.date("%Y%m%d", time2))
end

return mt
